﻿<!DOCTYPE html>
<html>
<head>
<!--
  Copyright (c) 2017-2018 Jean-Marc VIGLINO, 
  released under CeCILL-B (french BSD like) licence: http://www.cecill.info/
-->
  <title>ol-ext: Geolocation button</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <meta name="description" content="Openlayers control to handle geolocation." />
  <meta name="keywords" content="Openlayers, ol, control, GPS, location, geolocation" />

  <link rel="icon" type="image/png" href="https://openlayers.org/assets/theme/img/logo70.png" />

  <!-- android -->
  <meta name="mobile-web-app-capable" content="yes">
  <!-- iOS -->
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="translucent-black">
  <link rel="apple-touch-icon" href="https://openlayers.org/assets/theme/img/logo70.png" />
  <link rel="apple-touch-startup-image" href="https://openlayers.org/assets/theme/img/logo70.png" />

  <meta name="format-detection" content="telephone=no" />
  <meta name="msapplication-tap-highlight" content="no" />
  <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
  <!meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
  <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1" />

  <!-- Geolocation only works on https -->
  <script>
    if (location.protocol == 'http:' && !/^localhost/.test(location.host)) {
      location.href = window.location.href.replace(/^http:/,"https:");
    }
  </script>

  <link rel="stylesheet" href="../style.css" />

  <!-- jQuery -->
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.min.js"></script>

  <!-- Openlayers -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@latest/ol.css" />
  <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ol@latest/dist/ol.js"></script>

  
  <!-- ol-ext -->
  <link rel="stylesheet" href="../../dist/ol-ext.css" />
  <script type="text/javascript" src="../../dist/ol-ext.js"></script>
  <!-- Pointer events polyfill for old browsers, see https://caniuse.com/#feat=pointer -->
  <script src="https://unpkg.com/elm-pep"></script>

  <style>
    .ol-popup {
      text-align: center;
    }
  </style>

</head>
<body >
  <a href="https://github.com/Viglino/ol-ext" class="icss-github-corner"><i></i></a>

  <a href="../../index.html">
    <h1>ol-ext: Geolocation Bar</h1>
  </a>
  <div class="info">
    The <i>ol/control/GeolocationButton</i> is a simple control button to center on the device position.
    <br/>
    It centers the map and displays position. Use the <i>delay</i> option to change the time the position appears on the map.
    <br/>
    Listen to the <i>position</i> event to get position when activated.
    <br/>
    Use the <i>getInteraction()</i> method to get the ol <a href="map.interaction.geolocationdraw.html">GeolocationDraw</a> interation.  
  </div>

  <!-- Map div -->
  <div id="map" style="width:600px; height:400px;"></div>

  <script type="text/javascript">
    // Layers
    var layer = new ol.layer.Tile({ source: new ol.source.OSM() });
    
    // The map
    var map = new ol.Map ({
      target: 'map',
      view: new ol.View({
        zoom: 5,
        center: [261720, 5951081]
      }),
      layers: [layer]
    });


    // Add control
    var geoloc = new ol.control.GeolocationButton({
      title: 'Where am I?',
      delay: 2000 // 2s
    });
    map.addControl(geoloc);
    
    // Show position
    var here = new ol.Overlay.Popup({ positioning: 'bottom-center' });
    map.addOverlay(here);
    geoloc.on('position', function(e) {
      if (e.coordinate) here.show(e.coordinate, "You are<br/>here!");
      else here.hide();
    });

  </script>

</body>
</html>